package com.hksj.Intelligentmanagement.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hksj.Intelligentmanagement.common.Constants;
import com.hksj.Intelligentmanagement.common.Rest;
import com.hksj.Intelligentmanagement.dto.NurseDTO;
import com.hksj.Intelligentmanagement.service.NurseService;
import com.hksj.Intelligentmanagement.vo.NurseSimpleVo;
import com.hksj.Intelligentmanagement.vo.NurseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "麻醉人员信息管理")
@RestController
@RequestMapping("/api/anesthesia")
public class AnesthesiaController {
    @Autowired
    private NurseService nurseService;

    @ApiOperation("新增麻醉人员信息")
    @PostMapping("/createAnesthesia")
    public Rest createAnesthesia(@RequestBody @Validated(NurseDTO.Create.class) NurseDTO anesthesia){
        anesthesia.setType(Constants.TYPE_ANESTHESIA);
        return nurseService.createNurse(anesthesia);
    }

    @ApiOperation("修改麻醉人员信息")
    @PostMapping("/updateAnesthesia")
    public Rest updateAnesthesia(@RequestBody @Validated(NurseDTO.Update.class) NurseDTO anesthesia){
        anesthesia.setType(Constants.TYPE_ANESTHESIA);
        return nurseService.updateNurse(anesthesia);
    }

    @ApiOperation("删除麻醉人员信息")
    @DeleteMapping("/deleteAnesthesia/{id}")
    public Rest deleteAnesthesia(@PathVariable("id") String id){
        return nurseService.deleteNurse(id);
    }

    @ApiOperation("查询麻醉人员信息列表")
    @PostMapping("/listAnesthesia")
    public Rest<List<NurseSimpleVo>> listAnesthesia(@ApiParam(value = "麻醉人员姓名",required = false) @RequestParam(required = false) String anesthesiaName){
        return Rest.ok(nurseService.listNurse(anesthesiaName,Constants.TYPE_ANESTHESIA));
    }

    @ApiOperation("分页查询麻醉人员信息列表")
    @PostMapping("/pageAnesthesia")
    public Rest<IPage<NurseVo>> pageAnesthesia(
        @ApiParam(value = "麻醉人员姓名",required = false) @RequestParam(required = false) String anesthesiaName,
        @ApiParam(value = "麻醉人员工号",required = false) @RequestParam(required = false) String employeeNumber,
        @ApiParam(value = "麻醉人员等级id",required = false) @RequestParam(required = false) String anesthesiaLevelId,
        @ApiParam(value = "状态(0:未禁用,1:已禁用)",required = false) @RequestParam(required = false) String status,
        @ApiParam(value = "起始页",required = false,defaultValue = "1") @RequestParam(required = false,defaultValue = "1") Integer pageNum,
        @ApiParam(value = "每页大小",required = false,defaultValue = "10") @RequestParam(required = false,defaultValue = "10") Integer pageSize){
        IPage<NurseVo> pageInfo =  nurseService.pageNurse(new Page<>(pageNum,pageSize),anesthesiaName,employeeNumber,anesthesiaLevelId,status,Constants.TYPE_ANESTHESIA);
        return Rest.ok(pageInfo);
    }
}
